<template>
	<div>
		<Bread>
			<template v-slot:title>
				<el-breadcrumb-item v-for="(item, index) in titleList" :key="index"> {{ item }}</el-breadcrumb-item>

			</template>
		</Bread>
		<Card> </Card>
	</div>
</template>

<script>
import Bread from '../../components/Bread.vue'
import Card from '../../components/users/Card.vue'

export default {
	name: 'User',
	components: {
		Bread,
		Card,
	},
	data() {
		return {
			titleList: ['用户管理', '用户列表'],
			userList: '',
			pagination: {
				query: '',
				pagenum: 1,
				pagesize: 5,
			},
		}
	},
	methods: {
		getData() {
			this.$http
				.get('/users', {
					params: this.pagination,
				})
				.then(response => {
					const { data, meta } = response.data
					if (meta.status != 200) {
						this.$message.error('获取用户数据失败！')
					}
					this.userList = data
					this.$bus.$emit('userList', this.userList)
				})
				.catch(error => {
					console.log(error.message)
				})
		},
	},
	created() {
		this.$bus.$on('pagesize', data => {
			this.pagination.pagesize = data
			this.getData()
		})
		this.$bus.$on('pegenum', data => {
			this.pagination.pagenum = data
			this.getData()
		})
		this.$bus.$on('check', data => {
			this.pagination.query = data
			this.getData()
		})
		this.getData()
		this.$bus.$on('update', () => {

			this.getData()
		})
	},
	mounted() {
		this.$bus.$emit('pagination', this.pagination)

		this.$bus.$on('getDatas', () => {

			this.getData()
		})
	},
}
</script>

<style></style>
